Toggling Layer Visibility in Run Mode

Placing objects logically on different layers can enable the user to make certain layers invisible while not working with them.

The following example uses a button on a screen to toggle the visibility of a layer containing a Tank Control and a Text control.

To Toggle Layer Visibility in Run Mode

  1. Create a new Studio screen.
  2. First set up the layers on the View.
  1. Press F4 (or go to Layout > Layers) to open the Layers dialog box.
  2. Add a new layer and name it "Tank Layer."
  3. Leave the default layer ("Default") selected.
  1. Add a Standard Button to the View. In its (ObjectCode) field, type "btnShowHide." Set the Text property of the button to "Hide Tank." Set the [ButtonType] property to Standard. Ensure its Layer property is set to Default.
  2. Add a Tank Control to the View. Set its Layer property to Tank Layer.
  3. Add a Text control to the View. Set its Layer property to Tank Layer, and its [DisplayItem] property to Text.
  4. Add script to toggle layer visibility.
  1. Open the Script Editor and navigate to btnShowHide EventClick event.
  2. Enter the following script. This script checks the current visibility of the "Tank Layer" layer, then toggles it. It also updates the text of the Button to the relevant command.
Copy
Toggle Layer Visibility
Sub btnShowHide_EventClick()
Dim This : Set This = btnShowHide
    If TheView.Layer("Tank Layer") = True Then
        TheView.Layer("Tank Layer") = False
        This.Text = "Show Tank"
    Else
        TheView.Layer("Tank Layer") = True
        This.Text = "Hide Tank"
    End If
End Sub
  1. Save the screen and switch to Run mode to test the Show/Hide button.

The visibility of individual objects can be controlled through script using their respective Visible properties. Layer visibility can be more practical for controlling visibility of multiple objects, as in the above example. Another application of layer visibility is a screen that includes a type of "Edit mode," allowing the user to update properties in the system, then apply them. Switching into Edit mode would make these editing controls visible, and clicking an Apply button would hide them again and apply any changes.